package xc.com.ipscan;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.Socket;

import android.content.Context;
import android.util.Log;

public class IPutil {
	Context context;

	public IPutil(Context context) {
		this.context = context;
	}

	public static String c(String paramString) {
		String ModelName = "";
		Log.d("ScanUtils", "getmodel " + paramString);
		try {
			BufferedReader localBufferedReader = new BufferedReader(
					new InputStreamReader(
							Runtime.getRuntime()
									.exec("adb -s "
											+ paramString
											+ ":5555 shell cat /system/build.prop | grep \"product\"")
									.getInputStream()));
			StringBuffer localStringBuffer = new StringBuffer();
			String str = "";
			while ((str = localBufferedReader.readLine()) != null) {
				if (str.contains("ro.product.model")) {
					Log.d("ScanUtils", "getmodel rlt is " + str + "@"
							+ paramString);
					ModelName = str.substring(str.indexOf("=") + 1);
				} else {
					localStringBuffer.append(str);

				}
			}
			if (str == null) {
				Log.d("ScanUtils", "getmodel excute cmd finish");
			}
			Log.d("ScanUtils", "getmodel " + paramString + " cat product "
					+ str);

		} catch (IOException localIOException) {
			localIOException.printStackTrace();
		}
		return ModelName;
	}

	@SuppressWarnings("resource")
	public static boolean d(String paramString) {

		Socket localSocket = new Socket();
		InetSocketAddress localInetSocketAddress = new InetSocketAddress(
				paramString, 5555);
		try {
			localSocket.connect(localInetSocketAddress, 1000);
			return true;
		} catch (IOException localIOException) {
			return false;

		}

	}

	public static boolean e(String paramString) {
		boolean falg = true;
		Log.d("ScanUtils", "adb connect " + paramString + "   ___     "
				+ System.currentTimeMillis());
		try {
			Process localProcess = Runtime.getRuntime().exec(
					"adb connect " + paramString);
			int j = localProcess.waitFor();
			BufferedReader localBufferedReader = new BufferedReader(
					new InputStreamReader(localProcess.getInputStream()));
			StringBuffer localStringBuffer = new StringBuffer();
			String str = localBufferedReader.readLine();
			// Log.e("SCCSCCSCSCSCSCCSC", str);
			if (str != null) {
				localStringBuffer.append(str);
				Log.e("adb connect ", str);

				if (j != 0) {
					falg = false;
				}
				if (localStringBuffer.toString().contains("unable")) {
					falg = false;

				}
				if (localStringBuffer.toString().contains("Error")) {
					falg = false;
				}
			}
		} catch (IOException localIOException) {
			localIOException.printStackTrace();

		} catch (InterruptedException localInterruptedException) {
			localInterruptedException.printStackTrace();
		}
		return falg;

	}

	public static boolean f(String paramString) {
		Log.d("ScanUtils", "pingIp__" + paramString);
		boolean falg = false;
		try {
			Process localProcess = Runtime.getRuntime().exec(
					"ping -c 1 -w 0.5 " + paramString);
			int j = localProcess.waitFor();
			BufferedReader localBufferedReader = new BufferedReader(
					new InputStreamReader(localProcess.getInputStream()));
			StringBuffer localStringBuffer = new StringBuffer();
			String str = localBufferedReader.readLine();
			if (j == 0) {
				falg = true;
			}
			if (str == null) {
				Log.d("ScanUtils", "pingIp__" + paramString + "____ rlt is "
						+ localStringBuffer.toString());

			}
		} catch (IOException localIOException) {
			localIOException.printStackTrace();

		} catch (InterruptedException localInterruptedException) {
			localInterruptedException.printStackTrace();

		}
		return falg;
	}

	public static boolean g(String paramString) {
		boolean falg = true;
		try {
			Process localProcess = Runtime.getRuntime().exec(
					"adb disconnect " + paramString);
			Log.d("ScanUtils", "adb disconnect " + paramString);
			int j = localProcess.waitFor();
			BufferedReader localBufferedReader = new BufferedReader(
					new InputStreamReader(localProcess.getInputStream()));
			StringBuffer localStringBuffer = new StringBuffer();
			String str = localBufferedReader.readLine();
			if (str != null) {
				localStringBuffer.append(str);
				if (j != 0) {
					falg = false;
				}
				if (localStringBuffer.toString().contains("unable")) {
					falg = false;

				}
				if (localStringBuffer.toString().contains("Error")) {
					falg = false;
				}
			}
		} catch (IOException localIOException) {
			localIOException.printStackTrace();

		} catch (InterruptedException localInterruptedException) {
			localInterruptedException.printStackTrace();
		}
		return falg;

	}

	public static boolean h() {
		boolean falg = true;
		try {
			Process localProcess = Runtime.getRuntime().exec("adb disconnect ");
			int j = localProcess.waitFor();
			BufferedReader localBufferedReader = new BufferedReader(
					new InputStreamReader(localProcess.getInputStream()));
			StringBuffer localStringBuffer = new StringBuffer();
			String str = localBufferedReader.readLine();
			if (str != null) {
				localStringBuffer.append(str);
				if (j != 0) {
					falg = false;
				}
				if (localStringBuffer.toString().contains("unable")) {
					falg = false;

				}
				if (localStringBuffer.toString().contains("Error")) {
					falg = false;
				}
			}
		} catch (IOException localIOException) {
			localIOException.printStackTrace();

		} catch (InterruptedException localInterruptedException) {
			localInterruptedException.printStackTrace();
		}
		return falg;

	}
}
